home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / PowerPlant / 3D Additions 1.7 / 3D Additions / LStdCDEFControl.cp < prev    next >
Encoding:
Text File  |  1995-10-24  |  11.2 KB  |  375 lines  |  [TEXT/CWIE]

  1. /*
  2.     Public domain by Zig Zichterman
  3. */
  4. /*
  5.     LStdCDEFControl
  6.     
  7.     A collection of classes that derive from LStdControl but
  8.     use a CDEF other than 0. Useful mainly as CDEF-capable
  9.     replacements for
  10.         LStdButton
  11.         LStdCheckBox
  12.         LStdRadioButton
  13.         
  14.     Also, because my 3D CDEF implements icon buttons, you may
  15.     want to replace
  16.         LCicnButton
  17.         
  18.     10/24/95 jfr    added self-registration with URegistrar        
  19.     12/07/94    zz    initial write
  20. */
  21. #include "LStdCDEFControl.h"
  22.  
  23. #include <PP_Messages.h>
  24. #include <URegistrar.h>
  25.  
  26. /**************************************************************************
  27.     RegisterSelf()                                        [public, static]
  28. **************************************************************************/
  29.  
  30. void
  31. LStdCDEFButton::RegisterSelf()
  32. {
  33.     URegistrar::RegisterClass(class_ID,CreateFromStream);
  34. }
  35.  
  36.  
  37. /**************************************************************************
  38.     CreateFromStream()                                [public, static]
  39.     
  40.     Create a new button from the stream. Stream format is identical to
  41.     LStdControl and LStdButton--the CDEF is specified in the control kind
  42.     field (upper 12 bits)
  43. **************************************************************************/
  44. LStdCDEFButton *
  45. LStdCDEFButton::CreateFromStream(
  46.     LStream *    inStream)
  47. {
  48.     return new LStdCDEFButton(inStream);
  49. }
  50.  
  51. /**************************************************************************
  52.     LStdCDEFButton(void)                            [public]
  53.     
  54.     Default constructor. Make an unusable pane. Uses system CDEF.
  55. **************************************************************************/
  56. LStdCDEFButton::LStdCDEFButton()
  57.     : LStdControl((Int16) pushButProc)
  58. {
  59. }
  60.  
  61. /**************************************************************************
  62.     LStdCDEFButton(const LStdCDEFButton&)            [public]
  63.     
  64.     Copy constructor. Uses same CDEF as original
  65. **************************************************************************/
  66. LStdCDEFButton::LStdCDEFButton(
  67.     const LStdCDEFButton    &inOriginal)
  68.     : LStdControl(inOriginal)
  69. {
  70. }
  71.     
  72. /**************************************************************************
  73.     LStdCDEFButton(params)                            [public]
  74.     
  75.     Create from parameters. Specify a CDEF id or 0 for system CDEF
  76. **************************************************************************/
  77. LStdCDEFButton::LStdCDEFButton(
  78.     const SPaneInfo    &inPaneInfo,
  79.     MessageT        inValueMessage,
  80.     ResIDT            inTextTraitsID,
  81.     Str255            inTitle,
  82.     ResIDT            inCDEFid)
  83.         : LStdControl(inPaneInfo, inValueMessage, 0, 0, 0,
  84.             (inCDEFid << 4) + pushButProc,inTextTraitsID, inTitle, 0)
  85. {
  86. }
  87.     
  88. /**************************************************************************
  89.     LStdCDEFButton(params & ControlHandle)            [public]
  90.     
  91.     Create a button from an existing control handle. Since the control
  92.     handle already knows which CDEF to use, you don't need to supply
  93.     a CDEF id for this constructor.
  94. **************************************************************************/
  95. LStdCDEFButton::LStdCDEFButton(
  96.     const SPaneInfo    &inPaneInfo,
  97.     MessageT        inValueMessage,
  98.     ResIDT            inTextTraitsID,
  99.     ControlHandle    inMacControlH)
  100.     : LStdControl(inPaneInfo, inValueMessage, 0, 0, 0, pushButProc,
  101.                     inTextTraitsID, inMacControlH)
  102. {
  103. }
  104.  
  105. /**************************************************************************
  106.     LStdCDEFButton(stream)                            [public]
  107.     
  108.     Stream constructor. CDEF is specified in upper 12 bits of stream's
  109.     controlKind field.
  110. *************************************************************************/
  111. LStdCDEFButton::LStdCDEFButton(
  112.     LStream *    inStream)
  113.     : LStdControl(inStream)
  114. {
  115. }
  116.  
  117. /**************************************************************************
  118.     HotSpotResult()                                    [protected, virtual]
  119.                                                     [complete override ]
  120.  
  121.     Even though a click in a push button doesn't change its value,
  122.     it should broadcast its value message
  123. **************************************************************************/
  124. void
  125. LStdCDEFButton::HotSpotResult(
  126.     Int16 inHotSpot)
  127. {
  128.     BroadcastValueMessage();
  129. }
  130.  
  131. /**************************************************************************
  132.     RegisterSelf()                                        [public, static]
  133. **************************************************************************/
  134.  
  135. void
  136. LStdCDEFCheckBox::RegisterSelf()
  137. {
  138.     URegistrar::RegisterClass(class_ID,CreateFromStream);
  139. }
  140.  
  141.  
  142. /**************************************************************************
  143.     CreateFromStream()                                [public, static]
  144.     
  145.     Create a new checkbox from a stream. The CDEF is specified in the
  146.     upper 12 bits of the stream's control kind field
  147. **************************************************************************/
  148. LStdCDEFCheckBox *
  149. LStdCDEFCheckBox::CreateFromStream(
  150.     LStream *    inStream)
  151. {
  152.     return new LStdCDEFCheckBox(inStream);
  153. }
  154.  
  155. /**************************************************************************
  156.     LStdCDEFCheckBox(void)                            [public]
  157.     
  158.     Create a nigh-useless pane
  159. **************************************************************************/
  160. LStdCDEFCheckBox::LStdCDEFCheckBox(void)
  161.     : LStdControl()
  162. {
  163.     SetMaxValue(CheckBoxMax);
  164. }
  165.  
  166. /**************************************************************************
  167.     LStdCDEFCheckBox(const LStdCDEFCheckBox)        [public]
  168.     
  169.     Copy constructor. Uses same CDEF as original
  170. **************************************************************************/
  171. LStdCDEFCheckBox::LStdCDEFCheckBox(
  172.     const LStdCDEFCheckBox    &inOriginal)
  173.     : LStdControl(inOriginal)
  174. {
  175. }
  176.     
  177. /**************************************************************************
  178.     LStdCDEEFCheckBox(params-o-rama)                [public]
  179.     
  180.     Create a checkbox from parameters
  181. **************************************************************************/
  182. LStdCDEFCheckBox::LStdCDEFCheckBox(
  183.     const SPaneInfo    &inPaneInfo,
  184.     MessageT        inValueMessage,
  185.     Int32            inValue,
  186.     ResIDT            inTextTraitsID,
  187.     Str255            inTitle,
  188.     ResIDT            inCDEFid)
  189.     : LStdControl(inPaneInfo, inValueMessage, inValue, 0, CheckBoxMax,
  190.                 (inCDEFid << 4) + checkBoxProc, inTextTraitsID, inTitle, 0)
  191. {
  192. }
  193.     
  194. /**************************************************************************
  195.     LStdCDEFCheckBox(params & ControlHandle)        [public]
  196.     
  197.     Create a checkbox from parameters and a control handle. Since the
  198.     control handle already specifies a CDEF, you don't need to supply one
  199. **************************************************************************/
  200. LStdCDEFCheckBox::LStdCDEFCheckBox(
  201.     const SPaneInfo    &inPaneInfo,
  202.     MessageT        inValueMessage,
  203.     Int32            inValue,
  204.     ResIDT            inTextTraitsID,
  205.     ControlHandle    inMacControlH)
  206.     : LStdControl(inPaneInfo, inValueMessage, inValue, 0, CheckBoxMax,
  207.                     checkBoxProc, inTextTraitsID, inMacControlH)
  208. {
  209. }
  210.  
  211. /**************************************************************************
  212.     LStdCDEFCheckBox(stream)                        [public]
  213.     
  214.     Stream constructor. CDEF is in the upper 12 bits of stream's
  215.     control kind field
  216. **************************************************************************/
  217. LStdCDEFCheckBox::LStdCDEFCheckBox(
  218.     LStream *    inStream)
  219.     : LStdControl(inStream)
  220. {
  221. }
  222.     
  223. /**************************************************************************
  224.     HotSpotResult()                                    [protected, virtual]
  225.     
  226.     Toggle value.
  227. **************************************************************************/
  228. void
  229. LStdCDEFCheckBox::HotSpotResult(
  230.     Int16    inHotSpot)
  231. {
  232.     const Int32    OldValue    = GetValue();
  233. #ifndef    TRISTATE_TEST
  234.     Int32        newValue    = (OldValue == 0);
  235. #else
  236.     Int32        newValue    = OldValue + 1;
  237.     if (newValue > CheckBoxMax) {    
  238.         newValue = 0;
  239.     }
  240. #endif
  241.     SetValue(newValue);
  242. }
  243.  
  244.  
  245. /**************************************************************************
  246.     RegisterSelf()                                        [public, static]
  247. **************************************************************************/
  248.  
  249. void
  250. LStdCDEFRadioButton::RegisterSelf()
  251. {
  252.     URegistrar::RegisterClass(class_ID,CreateFromStream);
  253. }
  254.  
  255.  
  256. /**************************************************************************
  257.     CreateFromStream()                                [public, static]
  258.     
  259.     Create a radio button from a stream. Stream specifies CDEF id in
  260.     upper 12 bits of control kind field
  261. **************************************************************************/
  262. LStdCDEFRadioButton *
  263. LStdCDEFRadioButton::CreateFromStream(
  264.     LStream *    inStream)
  265. {
  266.     return new LStdCDEFRadioButton(inStream);
  267. }
  268.     
  269. /**************************************************************************
  270.     LStdCDEFRadioButton(void)                        [public]
  271.     
  272.     Create a nigh-useless pane
  273. **************************************************************************/
  274. LStdCDEFRadioButton::LStdCDEFRadioButton(void)
  275.     : LStdControl()
  276. {
  277.     SetMaxValue(RadioMax);
  278. }
  279.  
  280. /**************************************************************************
  281.     LStdCDEFRadioButton(params-o-rama)                [public]
  282.     
  283.     Create a radio button.
  284. **************************************************************************/
  285. LStdCDEFRadioButton::LStdCDEFRadioButton(
  286.     const SPaneInfo    &inPaneInfo,
  287.     MessageT        inValueMessage,
  288.     Int32            inValue,
  289.     ResIDT            inTextTraitsID,
  290.     Str255            inTitle,
  291.     ResIDT            inCDEFid,
  292.     Boolean            indented)
  293.     : LStdControl(inPaneInfo, inValueMessage, inValue, 0, RadioMax,
  294.             (inCDEFid << 4) + radioButProc + (indented ? indentHighlighted : 0),
  295.             inTextTraitsID, inTitle, 0)
  296. {
  297. }
  298.  
  299. /**************************************************************************
  300.     LStdCDEFRadioButton(params & ControlHandle)        [public]
  301.     
  302.     Create a radio button. CDEF is specified in ControlHandle.
  303. **************************************************************************/
  304. LStdCDEFRadioButton::LStdCDEFRadioButton(
  305.     const SPaneInfo    &inPaneInfo,
  306.     MessageT        inValueMessage,
  307.     Int32            inValue,
  308.     ResIDT            inTextTraitsID,
  309.     ControlHandle    inMacControlH)
  310.     : LStdControl(inPaneInfo, inValueMessage, inValue, 0, RadioMax,
  311.                     radioButProc, inTextTraitsID, inMacControlH)
  312. {
  313. }
  314.  
  315. /**************************************************************************
  316.     LStdCDEFRadioButton(const LStdCDEFRadioButton&)    [public]
  317.     
  318.     Copy constructor.
  319. **************************************************************************/
  320. LStdCDEFRadioButton::LStdCDEFRadioButton(
  321.     const LStdCDEFRadioButton    &inOriginal)
  322.     : LStdControl(inOriginal)
  323. {
  324. }
  325.  
  326. /**************************************************************************
  327.     LStdCDEFButton(LStream*)                        [public]
  328.     
  329.     Stream constructor
  330. **************************************************************************/
  331. LStdCDEFRadioButton::LStdCDEFRadioButton(
  332.     LStream *    inStream)
  333.     : LStdControl(inStream)
  334. {
  335. }
  336.  
  337. /**************************************************************************
  338.     HotSpotResult()                                    [protected, virtual]
  339.                                                     [complete override ]
  340.     Change value to 1 and broadcast the change so
  341.     radio groups can adapt
  342. **************************************************************************/
  343. void
  344. LStdCDEFRadioButton::HotSpotResult(
  345.     Int16    inHotSpot)
  346. {
  347.     SetValue(1);                    // Turn button ON
  348.     BroadcastMessage(msg_ControlClicked, (void*) this);
  349. }
  350.  
  351. /**************************************************************************
  352.     LStdCDEFIconButton(params)                        [public]
  353. **************************************************************************/
  354. LStdCDEFIconButton::LStdCDEFIconButton(
  355.     const SPaneInfo    &inPaneInfo,
  356.     MessageT        inValueMessage,
  357.     ResIDT            inIconID,
  358.     ResIDT            inCDEFid)
  359.     : LStdControl(inPaneInfo, inValueMessage, inIconID, min_Int16, max_Int16,
  360.             (inCDEFid << 4) + iconButProc, 0, 0, 0)
  361. {
  362. }
  363.  
  364. /**************************************************************************
  365.     HotSpotResult()                                    [protected, virtual]
  366.                                                     [complete override ]
  367.     like a pushButton, fire off a broadcast on click
  368. **************************************************************************/
  369. void
  370. LStdCDEFIconButton::HotSpotResult(
  371.     Int16    inHotSpot)
  372. {
  373.     BroadcastValueMessage();    
  374. }
  375.